const Axios = require("axios")
const axios = require('axios')
const cheerio = require('cheerio')
const fs = require('fs')
const writeStream = fs.createWriteStream('test.csv');
const url = 'http://www.xbmu.edu.cn/frontChannelPage.action?siteId=1&articleClassId=104';
axios.get(url)
  .then(function (response) {
    // handle success
    // console.log(response);
  })

const $ = cheerlo.load('<h2 class="title">Hello world</h2>');
$('h2.title').text('Hello there!');
//使用css选择符选择内容
console.log($('title').text());
console.log($('#container > div.list_main > div.list_right > div.list_right_main > ul > li').text());
$('#container > div.list_main > div.list_right > div.list_right_main > ul > li').each(function (index, element) {
  const newsDate = $(element).find('span').text();
  const item = $(element).find('a').text();
  const link = $(element).find('a').attr('href');
  console.log(newsDate, item, link);
})
$('#container > div.list_main > div.list_right > div.list_right_main > ul > li').each(function (index, element) {
  let newsDate = $(element).find('span').text();
  let newsTitle = $(element).find('a').text();
  let newsUrl = baseUrl + $(element).find('a').attr('href');
  console.log(newsDate, item, link);
  writeStream.write(`${newsDate}, ${item},${link} \n`);
})
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .then(function () {
    // always executed
  });